package com.example.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author YJC
 * @version V1.0
 * @description: job参数工具类
 * @date 2020-11-10 15:09
 */
public class JobParamUtils {

    /**
     * 解析Job任务参数为Map
     *
     * @param jobParameter job参数Json字符串
     * @return
     */
    public static Map<String, Object> parseJobParameter(String jobParameter) {
        Map<String, Object> parameterMap = new HashMap<>();
        if (StringUtils.isNotBlank(jobParameter)) {
            jobParameter = jobParameter.trim();
            JSONObject jsonObject = JSON.parseObject(jobParameter);
            Set<String> keys = jsonObject.keySet();
            for (String key : keys) {
                parameterMap.put(key, jsonObject.get(key));
            }
        }
        return parameterMap;
    }
}
